package com.version1_4.controller;

import com.alibaba.fastjson.JSONObject;
import com.version1_4.service.FeedService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by reeveslee on 16/5/3.
 */
@Controller
public class FeedController {
    private static final Logger LOGGER = Logger.getLogger(FeedController.class);

    @Autowired
    private FeedService feedService;

    /**
     * 添加话题评论
     *
     * @return
     */
    @RequestMapping(value = "/feed/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String add(@RequestBody JSONObject jsonObject) {
        return feedService.addFeed(jsonObject);
    }

    /**
     * 查看评论回复
     *
     * @param feedId
     * @return
     */
    @RequestMapping(value = "/feed/replys/{feedId}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String replys(@PathVariable("feedId") int feedId) {
        return feedService.replys(feedId);
    }

    /**
     * 添加回复
     *
     * @param jsonObject
     * @return
     */
    @RequestMapping(value = "/feed/reply/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String addReply(@RequestBody JSONObject jsonObject) {
        return feedService.addReply(jsonObject);
    }

    /**
     * 删除回复
     *
     * @param userId
     * @param replyId
     * @return
     */
    @RequestMapping(value = "/feed/reply/delete/{userId}/{replyId}", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String delReply(@PathVariable("userId") int userId, @PathVariable("replyId") int replyId) {
        return feedService.delReply(userId, replyId);
    }

    /**
     * 添加评论点赞
     *
     * @param feedId
     * @param userId
     * @return
     */
    @RequestMapping(value = "/feed/praise/add/{feedId}/{userId}", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String addPraise(@PathVariable("feedId") int feedId, @PathVariable("userId") int userId) {
        return feedService.addPraise(feedId, userId);
    }

    /**
     * 取消评论点赞
     *
     * @param feedId
     * @param userId
     * @return
     */
    @RequestMapping(value = "/feed/praise/delete/{feedId}/{userId}", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String deletePraise(@PathVariable("feedId") int feedId, @PathVariable("userId") int userId) {
        return feedService.deletePraise(feedId, userId);
    }

    /**
     * 收藏评论
     *
     * @param feedId
     * @param userId
     * @return
     */
    @RequestMapping(value = "/feed/collect/add/{userId}/{feedId}", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String collectAdd(@PathVariable("feedId") int feedId, @PathVariable("userId") int userId) {
        return feedService.collectAdd(feedId, userId);
    }

    /**
     * 删除收藏评论
     *
     * @param feedId
     * @param userId
     * @return
     */
    @RequestMapping(value = "/feed/collect/delete/{userId}/{feedId}", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String collectDel(@PathVariable("feedId") int feedId, @PathVariable("userId") int userId) {
        return feedService.collectDel(feedId, userId);
    }

    /**
     * 用户跟帖界面
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/feed/collect/{userId}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String collect(@PathVariable("userId") int userId) {
        return feedService.collect(userId);
    }

    /**
     * 举报评论
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/feed/report/{userId}/{feedId}", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String report(@PathVariable("userId") int userId, @PathVariable("feedId") int feedId) {
        return feedService.report(userId, feedId);
    }

    /**
     * 删除评论
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/feed/delete/{userId}/{feedId}", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String delete(@PathVariable("userId") int userId, @PathVariable("feedId") int feedId) {
        return feedService.delete(userId, feedId);
    }


}
